const request = require('request');
var req = require("../utils/router");
let { router, GetRouter, PostRouter } = req
let menu = [
    {
        name: "新·水印框", id: "1", list: [
            {
                id: "1",
                name: "水印",
                list: [
                    {
                        id: "1",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "2",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "3",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "4",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    }
                ]
            }
        ]
    },
    {
        name: "旧·水印框", id: "2", list: [
            {
                id: "1",
                name: "水印",
                list: [
                    {
                        id: "1",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "2",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "3",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "4",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    }
                ]
            }
        ]
    },
    {
        name: "全屏水印", id: "3", list: [
            {
                id: "1",
                name: "水印",
                list: [
                    {
                        id: "1",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "2",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "3",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    },
                    {
                        id: "4",
                        url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
                        name: "手机耳机"
                    }
                ]
            }
        ]
    },
    { name: "预览模板", id: "4" },
    { name: "小水印", id: "5" },
    { name: "瞳印", id: "6" },
    { name: "名片", id: "7" }
]
let home = {
    name: "铁拳杂货铺",
    url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
    list: [
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
            href: "www.baidu.com"
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
            href: "www.baidu.com"
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
            href: "www.baidu.com"
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
            href: "www.baidu.com"
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
            href: "www.baidu.com"
        },
    ]
}
let details = {
    id: "1",
    title: "这是个标题这是个标题这个是个标题",
    shop: 20,
    price: 30,
    url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
    list: [
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
        },
        {
            url: "http://162.14.64.133:8721/tieQuan/demo.jpg",
        },
    ]
}
// 菜单栏列表接口
new GetRouter().send('/list', function (res, data) {
    res.send({ code: 200, data: menu });
})
// 首页信息接口
new GetRouter().send('/home', function (res, data) {
    res.send({ code: 200, data: home });
})
// 商品详情接口
new GetRouter({ uuid: "id为商品唯一标识" }).send('/details', function (res, data) {
    console.log(data, "req, res,req, res,")
    res.send({
        code: 200, data: details
    });
})
// // 加入购物车接口
// new PostRouter({ uuid: "商品唯一标识" }).send('/shop', function (res, data) {
//     res.send({
//         code: 200, data: { msg: "商品添加成功" }
//     });
// })
// 定单列表接口
new GetRouter().send('/indent', function (res, data) {
    res.send({ code: 200, data: menu });
})

// 购物车接口
new GetRouter({ uuid: "id为商品唯一标识" }).send('/shopping', function (res, data) {
    res.send({ code: 200, data: menu });
})
// 取消定单接口
new GetRouter({ uuid: "id为商品唯一标识" }).send('/cancel/indent', function (res, data) {
    res.send({ code: 200, data: menu });
})
// 菜单栏列表接口
new GetRouter().send('/member/list', function (res, data) {
    res.send({ code: 200, data: menu });
})
// 商品详情接口
new GetRouter({ uuid: "uuid为商品唯一标识" }).send('/member/details', function (res, data) {
    res.send({
        code: 200, data: details
    });
})
// 联系客服的图片
new GetRouter().send('/support/staff', function (res, data) {
    res.send({
        code: 200, data: { url: "http://162.14.64.133:8721/tieQuan/QRcode.jpg" }
    });
})

new GetRouter().send('/openId', function (res, data) {
    console.log(data)
    let options = {
        method: 'POST',
        url: 'https://api.weixin.qq.com/sns/jscode2session?',
        formData: {
            appid: "wx7045c6b2645a9707",
            secret: "322e736f219fee9c5e53319d68e50ee4",
            js_code: data.code,
            grant_type: 'authorization_code'
        }
    };

    request(options, (error, response, body) => {
        if (error) { //请求异常时，返回错误信息
            res.json({
                "status": "error",
                "code": "ChasenKaso原创文章，转载请注明出处"
            })
        } else {
            //返回值的字符串转JSON
            let _data = JSON.parse(body);
            console.log(_data, "datadata")
            //根据返回值创建token
            // let _l = jwt.createHoursToken(req.body.code, _data.openid, _data.session_key);
            // let _s = jwt.createMonthToken(req.body.code, _data.openid, _data.session_key);

        }
    });
    res.send({ code: 200, data: menu });
})

module.exports = router